package com.qf.web.admin.controller;

import com.qf.aop.aspect.ApiOperationLog;
import com.qf.aop.aspect.ApiOperationLogTitle;
import com.qf.api.sys.vo.UploadFileVO;
import com.qf.core.constant.MinioConstant;
import com.qf.core.enums.common.BusinessTypeEnum;
import com.qf.core.response.ResponseResult;
import com.qf.core.utils.FileUtils;
import com.qf.minio.service.MinioService;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.validation.constraints.NotNull;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;


/**
 * @Author: sin
 * @Date: 2025/5/24 9:42
 * @Description: 文件上传，文件查看列表， 删除...
 **/
@Slf4j
@RestController
@ApiOperationLogTitle("文件模块")
@Tag(name = "07.文件接口")
@RequestMapping("/admin/file")
public class MinioController {

    @Resource
    private MinioService minioService;

    @PostMapping("/upload/img")
    @ApiOperationLog(desc = "上传图片",businessType = BusinessTypeEnum.UPLOAD)
    public ResponseResult<UploadFileVO> uploadFile(@NotNull MultipartFile file) {
        MultipartFile multipartFile = FileUtils.compressImageToMultipartFile(file, FileUtils.IMAGE_SCALE, FileUtils.IMAGE_QUALITY);
        String url = minioService.uploadFile(multipartFile, MinioConstant.BUCKET_NAME_AVATAR, FileUtils.generateUniqueFileName(multipartFile.getOriginalFilename()));
        return ResponseResult.success(UploadFileVO.builder().url(url).build());
    }

}
